﻿using System;
using System.Collections.Generic;
using System.Json;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using DX_DailyUtil_1._0._1.ks.objt;
using DX_DailyUtil_1._0._1.ks.objt.hitch;
using DX_DailyUtil_1._0._1.SerRef_WCF_Hitch;

namespace DX_DailyUtil_1._0._1.ks.util
{
    public class Util_Convert
    {
        public static Hitch convertTo_Hitch(JsonValue aJson)
        {
            Hitch _result = new Hitch();
            _result.Id = aJson["id"];
            _result.hitchNumber = aJson["hitch_number"];
            _result.HitchTitle = aJson["hitch_title"];
            _result.hitchType = aJson["hitch_type"];
            //for (int i = 0; i < aJson["RL_hitchLocate"].Count; i++)
            //{
            //    _result.HitchLocate.Add(new Hitch_Locate(aJson["RL_hitchLocate"][i]["Id"], aJson["RL_hitchLocate"][i]["machine"]["name"], aJson["RL_hitchLocate"][i]["machine"]["user"]["name"]));
            //}

            for (int i = 0; i < aJson["RL_labeler"].Count; i++)
            {
                _result.Labeler.Add(new User_Labeler(aJson["RL_labeler"][i]["Id"], aJson["RL_labeler"][i]["user"]["name"]));
            }

            for (int i = 0; i < aJson["RL_dealer"].Count; i++)
            {
                _result.Dealers.Add(new User_Dealer(aJson["RL_dealer"][i]["Id"], aJson["RL_dealer"][i]["user"]["name"]));
            }

            for (int i = 0; i < aJson["RL_clientContract"].Count; i++)
            {
                _result.Client.Add(new Hitch_Client(aJson["RL_clientContract"][i]["Id"], aJson["RL_clientContract"][i]["client"]["name"], aJson["RL_clientContract"][i]["client"]["user"]["name"]));
            }

            _result.HitchCause.Add(new Hitch_Cause(aJson["hitch_cause"]["id"], aJson["hitch_cause"]["name"]));

            return _result;
        }


        public static DB_Logic_Query.In_Where convertTo(List<String> aField, String aLogic, Object aValue)
        {
            DB_Logic_Query.In_Where _result = new DB_Logic_Query.In_Where();
            _result.field = aField;
            _result.logic = aLogic;
            _result.value = aValue;
            return _result;
        }

        public static DB_Logic_Query convertTo(String aTableName)
        {
            DB_Logic_Query _result = new DB_Logic_Query();
            _result.MTableName = aTableName;
            _result.MWhere = new System.Collections.Generic.List<DB_Logic_Query.In_Where>();
            _result.MSelect = new System.Collections.Generic.List<DB_Logic_Query.In_Select>();
            return _result;
        }
    }
}
